/*
 *  Borum, Boolean rule manipulator.
 *  Copyright (C) 2009 Jon Lennersten, Johan Hedin, Daniel Rosenberg
 *
 *  This file is part of Borum.
 *
 *  Borum is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Borum is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Borum.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.mawell.borum.demo;

import com.mawell.borum.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;

public class DisplayHitCountDemoFrame extends JFrame {

    public DisplayHitCountDemoFrame() throws HeadlessException {
        init();
        setSize(700, 500);

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        }
        );
        pack();
    }


    public void init() {
        getContentPane().setLayout(new GridBagLayout());
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("Borum display hit count demo");

        Rule rule = new Rule();
        ExampleTranslation et = new ExampleTranslation();

        OperandNode and1 = new OperandNode(OperandType.AND);
        and1.setTrans(et);
        and1.setHitCount(0);

        OperandNode or1 = new OperandNode(OperandType.OR);
        or1.setTrans(et);
        or1.setHitCount(3);

        java.util.List<OperandNode> andList = new ArrayList<OperandNode>();
        andList.add(or1);
        and1.setOps(andList);

        DateTerm term = new ExaminationDateTerm();
        term.setTranslationForTerm(et);
        term.setHitCount(0);

        java.util.List<Term> andTerms = new ArrayList<Term>();
        andTerms.add(term);
        and1.setTerms(andTerms);

        DateTerm term1 = new ExaminationDateTerm();
        term1.setTranslationForTerm(et);
        term1.setHitCount(0);

        DateTerm term2 = new ExaminationDateTerm();
        term2.setTranslationForTerm(et);
        term2.setHitCount(3);

        DateTerm term3 = new ExaminationDateTerm();
        term3.setTranslationForTerm(et);
        term3.setHitCount(-1);

        java.util.List<Term> orTerms = new ArrayList<Term>();
        orTerms.add(term1);
        orTerms.add(term2);
        orTerms.add(term3);

        or1.setTerms(orTerms);
        
        rule.setRootNode(and1);
        DisplayHitCountRuleView rView = new DisplayHitCountRuleView(rule, et, et);

        GridBagConstraints c = new GridBagConstraints();
        c.anchor = GridBagConstraints.NORTHWEST;
        c.weightx = 1; // add horizontal space to this component
        c.weighty = 1; // add vertical space to this component
        c.gridwidth = 1;
        c.gridheight = 1;
        c.fill = GridBagConstraints.BOTH; // fill vertically and horizontally if bigger than expected

        getContentPane().add(rView, c);
    }

    public static void main(String args[]) {

        EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DisplayHitCountDemoFrame().setVisible(true);
            }
        });
    }

}